using System;
using Microsoft.SharePoint;

namespace SharePoint.DataMapper
{
	[FieldMapper(typeof(SPFieldNumber), SPFieldType.Number)]
	public class FieldNumberMapper : FieldMapper
	{
		protected override SPField AddFieldInternal(ListDataContext context, SPFieldCollection collection, Type propertyType, FieldAttribute attribute)
		{
			SPFieldNumber field = (SPFieldNumber)base.AddFieldInternal(context, collection, propertyType, attribute);
			field.DisplayFormat = SPNumberFormatTypes.Automatic;
			field.ShowAsPercentage = attribute.ShowAsPercentage;
			field.MinimumValue = attribute.MinimumValue;
			field.MaximumValue = attribute.MaximumValue;
			return field;
		}

		protected override FieldAttribute GetFieldAttributeInternal(SPField field)
		{
			FieldAttribute attribute = base.GetFieldAttributeInternal(field);

			SPFieldNumber fieldNumber = field as SPFieldNumber;
			if (fieldNumber == null)
			{
				return attribute;
			}
			attribute.ShowAsPercentage = fieldNumber.ShowAsPercentage;
			attribute.MinimumValue = fieldNumber.MinimumValue;
			attribute.MaximumValue = fieldNumber.MaximumValue;
			return attribute;
		}
	}
}